<?php
/**

*/
class App_Auth_Storage_Session implements Zend_Auth_Storage_Interface
{
	protected $_session;
	protected $_area = "client";

	public function __construct($session, $module_name)
	{
		$this->_session  = $session;
		if ($module_name=="admin") $this->area = "admin";
		else $this->area = 'client';
	}

	/**
	 * Defined by Zend_Auth_Storage_Interface
	 *
	 * @return boolean
	 */
	public function isEmpty()
	{
		return !isset($this->_session->{$this->area.'user_id'});
	}

	/**
	 * Defined by Zend_Auth_Storage_Interface
	 *
	 * @return mixed
	 */
	public function read()
	{
		return array(
        		    'user_area' => $this->area,
                'user_id'=>$this->_session->{$this->area.'user_id'},
                'user_name'=>$this->_session->{$this->area.'user_name'},
                'user_role'=>$this->_session->{$this->area.'user_role'});
	}

	/**
	 * Defined by Zend_Auth_Storage_Interface
	 *
	 * @param  mixed $contents
	 * @return void
	 */
	public function write($contents)
	{
		//print_r($contents);
		$this->_session->{$this->area.'user_id'} = $contents['user_id'];
		$this->_session->{$this->area.'user_name'} = $contents['user_name'];
		$this->_session->{$this->area.'user_role'} = $contents['user_role'];
	}

	/**
	 * Defined by Zend_Auth_Storage_Interface
	 *
	 * @return void
	 */
	public function clear()
	{
		unset($this->_session->{$this->area});
		unset($this->_session->{$this->area.'user_id'});
		unset($this->_session->{$this->area.'user_name'});
		unset($this->_session->{$this->area.'user_role'});
	}

	public function getUserName()
	{
		return $this->_session->{$this->area.'user_name'};
	}

	public function setUserName($username)
	{
		$this->_session->{$this->area.'user_name'}=$username;
	}

	public function getUserId()
	{
		return $this->_session->{$this->area.'user_id'};
	}

	public function getUserRole()
	{
		return $this->_session->{$this->area.'user_role'};
	}
}
